home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Run Magazine ReRun 1991 September & October
/
rerun-1991-09-10.d64
/
number convert
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
11KB
|
391 lines
5 goto40
10 poke 53281,0
15 p$="menu runner":print"[147]"
17 printtab(14)"[159]loading me[158]n[159]u":print"[144]load"chr$(34)p$chr$(34)",8"
20 poke 198,4:poke 631,13:poke 632,82:poke 633,213:poke 634,13:end
25 print"[147]":poke 53280,14:poke 53281,14:sys 64738
30 printtab(w+len(s$))"[145] [157]":s$="":return
35 printtab(w)"[145] [157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157]";:return
40 sd=54272:fori=sdtosd+23:pokei,0:next:pokesd+24,15
45 poke53280,5:poke53281,0:poke788,52:print chr$(142);chr$(8)
50 print"[147] 1) decimal to binary conversion"
55 print" 2) binary to decimal conversion"
60 print" 3) decimal to hexadecimal conversion"
65 print" 4) hexadecimal to decimal conversion"
70 print" 5) rectangular to polar conversion"
75 print" 6) polar to rectangular conversion"
80 print" 7) english to metric conversions"
85 print" 8) metric to english conversions"
90 gosub755:poke198,0
95 get a$:if a$="" then95
100 a=val(a$)
105 on a goto125,245,405,560,765,990,1179,1404
110 if a$="[136]" then10
115 if a$="[140]" then25
120 goto95
125 print"[147]":poke53280,1:poke53281,1:d$="":w=22
130 print"[156] decimal to binary "
135 print"[144] enter decimal no.? ";:d$=""
137 if xx=12 then xx=0
138 if xx>6 then print" [157]";:goto 143
140 print"[164][157]";
143 get z$
145 if z$="m" then45
150 if z$="s" then245
155 if z$="[136]" then10
160 if z$="[140]" then25
165 if z$=chr$(20) then print:gosub755:gosub35:d$="":goto188
170 if z$=chr$(13) then print:s$=d$:gosub30:print"[145][145]":goto190
175 if len(d$)>4 then188
180 if z$<"0" or z$>"9" then188
185 print z$;:d$=d$+z$
188 xx=xx+1:goto 137
190 d=val(d$)
195 if d=0 or d>65535 then print:gosub35:d$="":goto140
200 gosub755
205 print:printtab(3)"[144]binary equivalent"
210 y=32768:z1=0
215 for x1=1 to 16
220 p=int(d/y):if p=-p then230
225 d=d-y
230 y=y/2
232 z1=z1+p:if z1=0 then 240
235 printtab(3)"[157]"p;:ifx1=4orx1=8orx1=12thenprint"";
240 next:print"":goto135
245 print"[147][144]":poke53280,1:poke53281,1:p=0:c$="":e$="":w=22
250 print"[156] binary to decimal "
255 print"[144] number of digits ? ";:p=0:c$="":e$=""
257 if xx>10 then xx=0
258 if xx>5 then print" [157]";:goto 263
260 print"[164][157]";
263 get b$
265 if b$="m" then45
270 if b$="s" then125
275 if b$="[136]" then10
280 if b$="[140]" then25
285 if b$=chr$(20) then print:gosub755:gosub35:c$="":goto307
290 if b$=chr$(13) then print:s$=c$:gosub30:print"[145][145]":goto310
295 if len(c$)>1 then307
300 if b$<"0" or b$>"9" then307
305 print b$;:c$=c$+b$
307 xx=xx+1:goto 257
310 c=val(c$):if c=0 or c>16 then print:gosub35:c$="":goto260
315 gosub755
320 print:print"[144] enter binary no. ? ";:k=c
322 if xx>10 then xx=0
323 if xx>5 then print" [157]";:goto 327
325 print"[164][157]";
327 get a$
330 if a$="m" then45
335 if a$="s" then125
340 if a$="[136]" then10
345 if a$="[140]" then25
350 if a$=chr$(20) then print:gosub755:gosub35:c=k:p=0:e$="":goto380
355 if a$=chr$(13) then print:s$=e$:gosub30:print"[145][145]":goto385
360 if c=0 then380
365 if a$<>"0" and a$<>"1" then380
370 print a$;:e$=e$+a$:a=val(a$)
375 c=c-1:p=p+2^c*a
380 xx=xx+1:goto322
385 if c<>0 then print:gosub35:c=k:p=0:e$="":goto325
390 gosub755
395 print:printtab(2)"[144] decimal equivalent";
400 print p"":goto255
405 print"[147]":poke53280,3:poke53281,3:g$="":w=27:goto415
410 printtab(w)"[145] [157][157][157][157][157][157][157][157][157][157]";:return
415 print"[156] decimal to hexadecimal "
420 print"[144] enter decimal no.? ";:g$=""
422 if xx>10 then xx=0
423 if xx>5 then print" [157]";:goto 428
425 print"[164][157]";
428 get f$
430 if f$="m" then45
435 if f$="s" then560
440 if f$="[136]" then10
445 if f$="[140]" then25
450 if f$=chr$(20) then print:gosub755:gosub410:g$="":goto472
455 if f$=chr$(13) then print:s$=g$:gosub30:print"[145][145]":goto475
460 if len(g$)>4 then472
465 if f$<"0" or f$>"9" then472
470 print f$;:g$=g$+f$
472 xx=xx+1:goto 422
475 g=val(g$)
480 if g=0 or g>65535 then print:gosub410:g$="":goto425
485 gosub755
490 print:printtab(4)"[144]hexadecimal equivalent";
495 h=4096:z1=0
500 for i=1 to 4
505 j=int(g/h):if j=-j then515
510 g=g-h*j
515 h=h/16:j$=str$(j)
520 if j=10 then j$=" a"
525 if j=11 then j$=" b"
530 if j=12 then j$=" c"
535 if j=13 then j$=" d"
540 if j=14 then j$=" e"
545 if j=15 then j$=" f"
547 z1=z1+j:if z1=0 then 555
550 print j$;
555 next:print"":goto420
560 print"[147]":poke53280,3:poke53281,3:q=0:n$="":t$="":w=27
565 print"[156] hexadecimal to decimal "
570 print"[144] number of digits ? ";:q=0:n$="":t$=""
572 if xx>10 then xx=0
573 if xx>5 then print" [157]";:goto 578
575 print"[164][157]";
578 get l$
580 if l$="m" then45
585 if l$="s" then405
590 if l$="[136]" then10
595 if l$="[140]" then25
600 if l$=chr$(20) then print:gosub755:gosub410:n$="":goto622
605 if l$=chr$(13) then print:s$=n$:gosub30:print"[145][145]":goto625
610 if len(n$)>0 then622
615 if l$<"1" or l$>"4" then622
620 print l$;:n$=n$+l$
622 xx=xx+1:goto 572
625 n=val(n$):ifn<1 or n>4then print:gosub410:n$="":goto575
630 gosub755
635 print:print"[144] enter hexadecimal no.? ";:v=n
637 if xx>8 then xx=0
638 if xx>4 then print" [157]";:goto 643
640 print"[164][157]";
643 get r$
645 if r$="m" then45
650 if r$="s" then405
655 if r$="[136]" then10
660 if r$="[140]" then25
665 if r$=chr$(20) then print:gosub755:gosub410:n=v:q=0:t$="":goto730
670 if r$=chr$(13) then print:s$=t$:gosub30:print"[145][145]":goto735
675 if n=0 then730
680 if r$="a" or r$="b" or r$="c" or r$="d" or r$="e" or r$="f"then690
685 if r$<"0" or r$>"9" then730
690 print r$;:t$=t$+r$:r=val(r$)
695 if r$="a" then r=10
700 if r$="b" then r=11
705 if r$="c" then r=12
710 if r$="d" then r=13
715 if r$="e" then r=14
720 if r$="f" then r=15
725 n=n-1:q=q+16^n*r
730 xx=xx+1:goto 637
735 if n<>0 then print:gosub410:n=v:q=0:t$="":goto640
740 gosub755
745 print:printtab(2)"[144] decimal equivalent";
750 print q"":goto570
755 pokesd+5,8:pokesd+6,240:pokesd,0:pokesd+1,90:pokesd+4,17:fors=1to100:next
760 pokesd+4,0:pokesd,0:pokesd+1,0:return
765 print"[147]":poke53280,0:poke53281,0:o$="":u$="":w=21
770 print"[156] rectangular to polar "
775 print" x coordinate ? [154]";:o$="":u$=""
777 if xx>10 then xx=0
778 if xx>5 then print" [157]";:goto 783
780 print"[164][157]";
783 get a$
785 if a$="m" then45
790 if a$="s" then990
795 if a$="[136]" then10
800 if a$="[140]" then25
805 if a$=chr$(20) then print:gosub755:gosub35:o$="":goto832
810 if a$=chr$(13) then print:s$=o$:gosub30:print"[145][145]":goto835
815 if len(o$)>6 then832
820 if a$="." or a$="-" then830
825 if a$<"0" or a$>"9" then832
830 print a$;:o$=o$+a$
832 xx=xx+1:goto 777
835 o=val(o$):ifo$=""or(o<-999.99 or o>999.99)then print:gosub35:o$="":goto780
840 if o$<>right$(str$(o),len(o$))then print:gosub35:o$="":goto780
845 gosub755
850 print" y coordinate ? [154]";:u$=""
852 if xx>10 then xx=0
853 if xx>5 then print" [157]";:goto 858
855 print"[164][157]";
858 get a$
860 if a$="m" then45
865 if a$="s" then990
870 if a$="[136]" then10
875 if a$="[140]" then25
880 if a$=chr$(20) then print:gosub755:gosub35:u$="":goto907
885 if a$=chr$(13) then print:s$=u$:gosub30:print"[145][145]":goto910
890 if len(u$)>6 then907
895 if a$="." or a$="-"then905
900 if a$<"0" or a$>"9" then907
905 print a$;:u$=u$+a$
907 xx=xx+1:goto 852
910 u=val(u$):ifu$=""or(u<-999.99 or u>999.99)then print:gosub35:u$="":goto855
915 if u$<>right$(str$(u),len(u$))then print:gosub35:u$="":goto855
920 gosub755
925 v=sqr(o^2+u^2)
930 if o=0 then960
935 y=atn(u/o)*180/(NULL)
940 if o<0 and u<0 then y=y+180
945 if o<0 and u>=0 then y=180+y
950 if o>0 and u<0 then y=360+y
955 goto970
960 if u>0 then y=90
965 if u<0 then y=270
970 v1=abs(v)*100+.5:v=sgn(v)*int(v1)/100
975 y1=abs(y)*100+.5:y=sgn(y)*int(y1)/100
980 print" polar equivalent[158]";v"[157]<"y:v=0:y=0
985 print"":goto775
990 print"[147]":poke53280,0:poke53281,0:o$="":u$="":w=21
995 print"[156] polar to rectangular "
1000 print" modulus ? [154]";:o$="":u$=""
1002 if xx>10 then xx=0
1003 if xx>5 then print" [157]